/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.res0w.SMMS.admin;

import com.res0w.SMMS.ds.SettingSchedule;
import com.res0w.SMMS.ds.SignUpCacheList;
import com.res0w.SMMS.factory.DataBaseOperate;
import com.res0w.SMMS.factory.fullItemsName;
import com.res0w.SMMS.fuction.DBInit;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author res0w
 * @since 2009-9-22
 * @version 0.1
 *
 */
public class Schedule {

    private ArrayList list = new ArrayList();
    private DataBaseOperate db;
    public int ItemsPriority;
    public String itemsName;
    public String itemsDate;
    public String itemsLocation;
    public int isFinished;
    public String academy;
    public String specialField;
    public String classes;
    public String sId;
    public String sName;
    public int sex;
    public String joinItems;
    public ArrayList scheduleList = new ArrayList();

    public Schedule() {
        db = new DataBaseOperate();
        list.clear();
    }

    public void scheduleUpdate(boolean isExe) {
        SettingSchedule ss = new SettingSchedule();
        ss.itemsPriority = ItemsPriority;
        ss.itemsName = itemsName;
        ss.itemsDate = itemsDate;
        ss.itemsLocation = itemsLocation;
        for (int i = 0; i < ss.exeSqls().length; i++) {
            list.add(ss.exeSqls()[i]);
        }
        if (isExe) {
            db.dbUpdateBatch(list);
        }
    }

    public void scheduleRead() {
        SettingSchedule ss = new SettingSchedule();
        ss.readSqls();
        scheduleList = ss.scheduleList;
    }

    public void onlyExe4Schedule() {
        clearTable("setting_schedule");
        db.dbUpdateBatch(list);
    }

    public void onlyExe4CacheSchedule() {
        db.dbUpdateBatch(list);
    }

    public void clearTable(String tableName) {
        DBInit dbi = new DBInit();
        dbi.clearTable(tableName);
    }

    public Object[] readFullItems() {
        ArrayList ItemsList = new ArrayList();
        try {
            ResultSet rs = null;

            DataBaseOperate database = new DataBaseOperate();
            String sqlAlter = "select itemsName,sex from setting_alteritems";
            String sqlRelay = "select itemsName,sex from setting_relay";
            rs = database.dbQueryMuti(sqlAlter);
            while (rs.next()) {
                ItemsList.addAll(fullItemsName.fullName(rs.getString(1), rs.getInt(2)));
            }
            rs = database.dbQueryMuti(sqlRelay);
            while (rs.next()) {
                ItemsList.addAll(fullItemsName.fullName(rs.getString(1), rs.getInt(2)));
            }
        } catch (SQLException ex) {
            Logger.getLogger(Schedule.class.getName()).log(Level.SEVERE, null, ex);
        }
        Object[] returnList = new Object[ItemsList.size()];
        for (int i = 0; i < ItemsList.size(); i++) {
            returnList[i] = ItemsList.get(i);
        }
        return returnList;
    }

    public void schedule() {
        SettingSchedule ssn = new SettingSchedule();

        ssn.itemsPriority = ItemsPriority;
        ssn.itemsName = itemsName;
        ssn.itemsDate = itemsDate;
        ssn.itemsLocation = itemsLocation;
        ssn.isFinished = isFinished;

        for (int i = 0; i < ssn.exeSqls().length; i++) {
            list.add(ssn.exeSqls()[i]);
        }
    }

    public void cacheListUpdate(boolean isExe) {
        SignUpCacheList ssn = new SignUpCacheList();

        ssn.academy = academy;
        ssn.classes = classes;
        ssn.specialField = specialField;
        ssn.sID = sId;
        ssn.sName = sName;
        ssn.sex = sex;
        ssn.joinItems = joinItems;

        for (int i = 0; i < ssn.exeSqls().length; i++) {
            list.add(ssn.exeSqls()[i]);
        }
        if (isExe) {
            db.dbUpdateBatch(list);
        }
    }
}
